class Solution(object):
    def partitionLabels(self, s):
        """
        :type s: str
        :rtype: List[int]
        """
        alpha_dict = {}
        #获取每个字母最远出现的位置
        for i in range(len(s)):
            alpha_dict[s[i]] = i

        #重新遍历，若当前字段位置等于最远位置，则切割
        ans = []
        left = 0
        j = 0
        for i in range(len(s)):
            j = max(j, alpha_dict[s[i]])
            if j == i:
                ans.append(i - left + 1)
                left = i + 1
        return ans
